package com.hc.javabasestudyproject.feature.methodquote;

import com.hc.javabasestudyproject.feature.entity.Author;
import com.hc.javabasestudyproject.feature.entity.DataUtils;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Author: huangcheng
 * @CreateTime: 2023-11-22  14:25
 * @Description:
 * @Version: 1.0
 */
public class Test {
    public static void main(String[] args) {
        List<Author> authorList = DataUtils.getAuthors();
        List<String> collect1 = authorList.stream()
                .map(new Function<Author, Integer>() {
                    @Override
                    public Integer apply(Author author) {
                        return author.getAge();
                    }
                }).map(new Function<Integer, String>() {
                    @Override
                    public String apply(Integer age) {
                        return String.valueOf(age);
                    }
                }).collect(Collectors.toList());

        List<String> collect2 = authorList.stream()
                .map(author -> author.getAge()).map(age -> String.valueOf(age)).collect(Collectors.toList());
        List<String> collect3 = authorList.stream()
                .map(Author::getAge).map(String::valueOf).collect(Collectors.toList());

        System.out.println(collect1);
        System.out.println(collect2);
        System.out.println(collect3);
    }
}
